home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 June / EnigmA AMIGA RUN 19 (1997)(G.R. Edizioni)(IT)[!][issue 1997-06][EAR-CD III].iso / recent1 / apic1805.lha / APIC / examples / IBMKEY25.ASM < prev    next >
Assembly Source File  |  1997-05-05  |  39KB  |  1,319 lines

  1. ;KEY.ASM
  2. ;   IBM keyboard to Amiga Converter
  3. ;
  4. ;
  5. ;        list p=16c84, f=inhx8m  ;Enter device name 
  6. ;        include "p16c84.inc"
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13. ;*******************following lines added**************************************
  14. ;
  15. ;The original source is Copyright © 1997 Stephen Marsden, taken from
  16. ;EPic12.lha, this changes are made to assemble MPASM source on Amiga
  17. ;with PICAsm.
  18. ;    
  19. ;
  20. ;Dirk Düsterberg
  21. ;
  22. ;            [InterNet] duesterb@unixserv.rz.fh-hannover.de
  23. ;            [Homepage] http://linux.rz.fh-hannover.de/~duesterb/
  24. ;
  25.  
  26.  
  27.  
  28.         list p=16c84         ;Enter device name 
  29.         include "includes:p16cxx.inc"
  30.  
  31. ;16c84 spezial register (EECON1) assigns:
  32.  
  33.     CBLOCK    0
  34.            RD
  35.        WR
  36.        WREN
  37.        WRERR
  38.        EEIF
  39.     ENDC
  40.  
  41. ;******************************************************************************
  42.  
  43.  
  44.  
  45.  
  46.  
  47. #DEFINE PAGE0   bcf     STATUS,RP0          
  48. #DEFINE PAGE1   bsf     STATUS,RP0          
  49.  
  50. ;
  51. ;------------------------------------------------------
  52. ;Please define ScratchPadRam here:
  53. ;If you are using PIC16C5X define "ScratchPadRam equ 0x10" 
  54. ;else define "ScratchPadRam equ 0x20"
  55. ;-------------------------------------------------------
  56. ;
  57. ScrollLock  equ     0x0
  58. NumLock     equ     0x1
  59. CapsLock    equ     0x2
  60. Kclk        equ     0x1
  61. Kdat        equ     0x0
  62. Aclk        equ     0x4
  63. Adat        equ     0x3
  64. Arst        equ     0x2
  65. Ctrlbit     equ     0x0
  66. RAmigabit   equ     0x1
  67. LAmigabit   equ     0x2
  68. Keytype     equ     0x0
  69. Resetype    equ     0x1
  70. ;
  71. ;
  72. ScratchPadRam   equ     0x0C
  73. ;
  74. Capbit      equ     ScratchPadRam+0x0
  75. Capdown     equ     ScratchPadRam+0x1
  76. CtrlDown    equ     ScratchPadRam+0x2
  77. RESET       equ     ScratchPadRam+0x3
  78. Lights      equ     ScratchPadRam+0x4
  79. Count3      equ     ScratchPadRam+0x5
  80. ATparity    equ     ScratchPadRam+0x6
  81. Make        equ     ScratchPadRam+0x7
  82. Charbad     equ     ScratchPadRam+0x8
  83. Oldchar     equ     ScratchPadRam+0x9
  84. Amigachar   equ     ScratchPadRam+0xA
  85. Count1      equ     ScratchPadRam+0xB
  86. Count2      equ     ScratchPadRam+0xC
  87. ATchar      equ     ScratchPadRam+0xD
  88. tableoffset equ     ScratchPadRam+0xE
  89. AltConfig   equ     ScratchPadRam+0xF
  90. Savechar    equ     ScratchPadRam+0x10
  91. returnvalue equ     ScratchPadRam+0x11
  92. eeaddress   equ     ScratchPadRam+0x12
  93. eedata      equ     ScratchPadRam+0x13
  94. win95       equ     ScratchPadRam+0x14
  95. Savechar2   equ     ScratchPadRam+0x15
  96. ;
  97. ;        
  98.         org     0x0
  99.         goto    start
  100.  
  101. ATtb1 
  102.         movwf       PCL                  
  103.         retlw       0x4F            ;F9
  104.         retlw       0x0               
  105.         retlw       0x57            ;F5
  106.         retlw       0x5B            ;F3
  107.         retlw       0x5F            ;F1
  108.         retlw       0x5D            ;F2
  109.         retlw       0x41            ;F12=help
  110.         retlw       0x0
  111.         retlw       0x4D            ;F10
  112.         retlw       0x51            ;F8
  113.         retlw       0x55            ;F6
  114.         retlw       0x59            ;F4
  115.         retlw       0x7B            ;TAB
  116.         retlw       0xFF            ;~
  117.         retlw       0x0
  118.  
  119.         retlw       0x0
  120.         retlw       0x37            ;Left ALT
  121.         retlw       0x3F            ;Left SHIFT
  122.         retlw       0x0
  123.         goto    lctrl               ;Left Ctrl
  124.         retlw       0xDF            ;Q
  125.         retlw       0xFD            ;1
  126.         retlw       0x0
  127.         retlw       0x0
  128.         retlw       0x0
  129.         retlw       0x9D            ;Z
  130.         retlw       0xBD            ;S
  131.         retlw       0xBF            ;A
  132.         retlw       0xDD            ;W
  133.         retlw       0xFB            ;2
  134.         retlw       0x0
  135.  
  136.         retlw       0x0
  137.         retlw       0x99            ;C
  138.         retlw       0x9B            ;X
  139.         retlw       0xBB            ;D
  140.         retlw       0xDB            ;E
  141.         retlw       0xF7            ;4
  142.         retlw       0xF9            ;3
  143.         retlw       0x0
  144.         retlw       0x0
  145.         retlw       0x7F            ;SPACE
  146.         retlw       0x97            ;V
  147.         retlw       0xB9            ;F
  148.         retlw       0xD7            ;T
  149.         retlw       0xD9            ;R
  150.         retlw       0xF5            ;5
  151.         retlw       0x0
  152.  
  153.         retlw       0x0
  154.         retlw       0x93            ;N
  155.         retlw       0x95            ;B
  156.         retlw       0xB5            ;H
  157.         retlw       0xB7            ;G
  158.         retlw       0xD5            ;Y
  159.         retlw       0xF3            ;6
  160.         retlw       0x0
  161.         retlw       0x0
  162.         retlw       0x0
  163.         retlw       0x91            ;M
  164.         retlw       0xB3            ;J
  165.         retlw       0xD3            ;U
  166.         retlw       0xF1            ;7
  167.         retlw       0xEF            ;8
  168.         retlw       0x0
  169.  
  170.         retlw       0x0
  171.         retlw       0x8F            ;<
  172.         retlw       0xB1            ;K
  173.         retlw       0xD1            ;I
  174.         retlw       0xCF            ;O
  175.         retlw       0xEB            ;0
  176.         retlw       0xED            ;9
  177.         retlw       0x0
  178.         retlw       0x0
  179.         retlw       0x8D            ;>
  180.         retlw       0x8B            ;/
  181.         retlw       0xAF            ;L
  182.         retlw       0xAD            ; ';'
  183.         retlw       0xCD            ;P
  184.         retlw       0xE9            ;-
  185.         retlw       0x0
  186.  
  187.         retlw       0x0
  188.         retlw       0x0
  189.         retlw       0xAB            ;@
  190.         retlw       0x0
  191.         retlw       0xCB            ;[
  192.         retlw       0xE7            ;=
  193.         retlw       0x0
  194.         retlw       0x0
  195.         retlw       0x3B            ;CAPS LOCK?
  196.         retlw       0x3D            ;Right SHIFT
  197.         retlw       0x77            ;RETURN
  198.         retlw       0xC9            ;]
  199.         retlw       0x0
  200.         retlw       0xA9            ;#=right foreign key
  201.         retlw       0x0
  202.         retlw       0x0
  203.  
  204.         retlw       0x0
  205.         retlw       0x9F            ;\ (next to left shift on AT keyboard)
  206.         retlw       0x0
  207.         retlw       0x0
  208.         retlw       0x0
  209.         retlw       0x0
  210.         retlw       0x7D            ;Back SPACE
  211.         retlw       0x0
  212.         retlw       0x0
  213.         retlw       0xC5            ;1 keypad
  214.         retlw       0x0
  215.         retlw       0xA5            ;4 keypad
  216.         retlw       0x85            ;7 keypad
  217.         retlw       0x0
  218.         retlw       0x0
  219.         retlw       0x0
  220.  
  221.         retlw       0xE1            ;0 keypad
  222.         retlw       0x87            ;dot keypad
  223.         retlw       0xC3            ;2 keypad
  224.         retlw       0xA3            ;5 keypad
  225.         retlw       0xA1            ;6 keypad
  226.         retlw       0x83            ;8 keypad
  227.         retlw       0x75            ;ESCAPE!
  228.         retlw       0x4B            ;Number Lock=( keypad   
  229.         retlw       0xE5            ;F11=\
  230.         retlw       0x43            ;+ keypad
  231.         retlw       0xC1            ;3 keypad
  232.         retlw       0x6B            ;- keypad
  233.         retlw       0x45            ;* keypad
  234.         retlw       0x81            ;9 keypad
  235.         retlw       0x49            ;scroll Lock=) keypad 
  236.         retlw       0x0
  237.  
  238. ATtb2:
  239.         retlw       0x0
  240.         retlw       0x0
  241.         retlw       0x0
  242.         retlw       0x53            ;F7
  243.         goto    prtscreen           ;print screen=R Amiga P  
  244.         retlw       0x0
  245.         retlw       0x0
  246.         retlw       0x0
  247.         retlw       0x0
  248.         retlw       0x0
  249.         retlw       0x0
  250.         retlw       0x0
  251.         retlw       0x0
  252.         retlw       0x0
  253.         retlw       0x0
  254.         retlw       0x0
  255.  
  256.         retlw       0x0
  257.         retlw       0x35            ;Right ALT
  258.         retlw       0x0
  259.         retlw       0x0
  260.         goto    rctrl               ;Right CTL
  261.         retlw       0x0
  262.         retlw       0x0
  263.         retlw       0x0
  264.         retlw       0x0
  265.         retlw       0x0
  266.         retlw       0x0
  267.         retlw       0x0
  268.         retlw       0x0
  269.         retlw       0x0
  270.         retlw       0x0
  271.         retlw       0x33            ;Left Win=Left Amiga
  272.  
  273.         retlw       0x0
  274.         retlw       0x0
  275.         retlw       0x0
  276.         retlw       0x0
  277.         retlw       0x0
  278.         retlw       0x0
  279.         retlw       0x0
  280.         retlw       0x31            ;Right Win=Right Amiga
  281.         retlw       0x0
  282.         retlw       0x0
  283.         retlw       0x0
  284.         retlw       0x0
  285.         retlw       0x0
  286.         retlw       0x0
  287.         retlw       0x0
  288.         goto    swapscreen          ;Menu Key=L-Amiga M
  289.         
  290.         retlw       0x0
  291.         retlw       0x0
  292.         retlw       0x0
  293.         retlw       0x0
  294.         retlw       0x0
  295.         retlw       0x0
  296.         retlw       0x0
  297.         retlw       0x0
  298.         retlw       0x0
  299.         retlw       0x0
  300.         retlw       0x0
  301.         retlw       0x0
  302.         retlw       0x0
  303.         retlw       0x0
  304.         retlw       0x0
  305.         retlw       0x0
  306.  
  307.         retlw       0x0
  308.         retlw       0x0
  309.         retlw       0x0
  310.         retlw       0x0
  311.         retlw       0x0
  312.         retlw       0x0
  313.         retlw       0x0
  314.         retlw       0x0
  315.         retlw       0x0
  316.         retlw       0x0
  317.         retlw       0x8B            ;/key, supposedly
  318.         retlw       0x0
  319.         retlw       0x0
  320.         retlw       0x0
  321.         retlw       0x0
  322.         retlw       0x0
  323.  
  324.         retlw       0x0
  325.         retlw       0x0
  326.         retlw       0x0
  327.         retlw       0x0
  328.         retlw       0x0
  329.         retlw       0x0
  330.         retlw       0x0
  331.         retlw       0x0
  332.         retlw       0x0
  333.         retlw       0x0
  334.         retlw       0x79            ;Numeric Enter
  335.         retlw       0x0
  336.         retlw       0x0
  337.         retlw       0x0
  338.         retlw       0x0
  339.         retlw       0x0
  340.  
  341.         retlw       0x0
  342.         retlw       0x0
  343.         retlw       0x0
  344.         retlw       0x0
  345.         retlw       0x0
  346.         retlw       0x0
  347.         retlw       0x0
  348.         retlw       0x0
  349.         retlw       0x0
  350.         goto    endkey              ;End=Shift right-cursor  
  351.         retlw       0x0
  352.         retlw       0x61            ;Cursor Left
  353.         goto    home                ;Home=Shift left-cursor  
  354.         retlw       0x0
  355.         retlw       0x0
  356.         retlw       0x63            ;MACRO key=control
  357.  
  358.         goto    insert              ;Insert=Right Amiga 7
  359.         retlw       0x73            ;Delete
  360.         retlw       0x65            ;Cursor Down
  361.         retlw       0x0
  362.         retlw       0x63            ;Cursor Right
  363.         retlw       0x67            ;Cursor Up
  364.         retlw       0x0
  365.         retlw       0x0
  366.         retlw       0x0
  367.         retlw       0x0
  368.         goto    pagedown            ;Page Down=Shift down-cursor
  369.         retlw       0x0
  370.         goto    prtscreen           ;print screen=Right Amiga P
  371.         goto    pageup              ;Page up=Shift up-cursor
  372.         goto    break               ;Break=Ctrl-C
  373. ;        retlw       0x0
  374.  
  375.  
  376.  
  377. ; *** Left Control key ***
  378. lctrl
  379.         btfsc   win95,0x0
  380.         retlw   0x39                ; ctrl
  381.         retlw   0x33                ; left Amiga
  382.  
  383. ; *** Right Control key ***
  384. rctrl
  385.         btfsc   win95,0x0
  386.         retlw   0x39                ; ctrl
  387.         retlw   0x31                ; right Amiga
  388.         
  389.  
  390. ; *** Menu = Left Amiga-M ***
  391. swapscreen
  392.         movlw   0x33                ; Left Amiga pressed
  393.         call    actualtransmit
  394.         movlw   0x91                ; M pressed & released
  395.         call    sendmessage
  396.         movlw   0x32                ; Left Amiga released
  397.         call    actualtransmit
  398.         retlw   0x0          
  399.  
  400.  
  401. ; *** Prt Scrn Key = Right Amiga-P ***
  402. prtscreen
  403.         movlw   0x31                ; Right Amiga pressed
  404.         call    actualtransmit
  405.         movlw   0xCD                ; P pressed & released
  406.         call    sendmessage
  407.         movlw   0x30                ; Right Amiga released
  408.         call    actualtransmit
  409.         retlw   0x0          
  410.  
  411.  
  412.  
  413. ; *** End Key = Shift right-cursor ***
  414. endkey
  415.         movlw   0x3D                ; Right shift pressed
  416.         call    actualtransmit
  417.         movlw   0x63                ; right-cursor pressed & released
  418.         call    sendmessage
  419.         movlw   0x3C                ; Right shift released
  420.         call    actualtransmit
  421.         retlw   0x0          
  422.  
  423.  
  424.  
  425. ; *** Home Key = Shift left-cursor ***
  426. home
  427.         movlw   0x3D                ; Right shift pressed
  428.         call    actualtransmit
  429.         movlw   0x61                ; left-cursor pressed & released
  430.         call    sendmessage
  431.         movlw   0x3C                ; Right shift released
  432.         call    actualtransmit
  433.         retlw   0x0          
  434.  
  435.  
  436.  
  437. ; *** PageDown Key = Shift down-cursor ***
  438. pagedown
  439.         movlw   0x3D                ; Right shift pressed
  440.         call    actualtransmit
  441.         movlw   0x65                ; down-cursor pressed & released
  442.         call    sendmessage
  443.         movlw   0x3C                ; Right shift released
  444.         call    actualtransmit
  445.         retlw   0x0          
  446.  
  447.  
  448.  
  449. ; *** Pageup Key = Shift up-cursor ***
  450. pageup
  451.         movlw   0x3D                ; Right shift pressed
  452.         call    actualtransmit
  453.         movlw   0x67                ; up-cursor pressed & released
  454.         call    sendmessage
  455.         movlw   0x3C                ; Right shift released
  456.         call    actualtransmit
  457.         retlw   0x0          
  458.  
  459.  
  460.  
  461. ; *** Insert Key = Right Amiga 7 ***
  462. insert
  463.         movlw   0x31                ; Right Amiga pressed
  464.         call    actualtransmit
  465.         movlw   0xF1                ; 7 pressed & released
  466.         call    sendmessage
  467.         movlw   0x30                ; Right Amiga released
  468.         call    actualtransmit
  469.         retlw   0x0          
  470.  
  471.  
  472.  
  473. ; *** Break Key = Ctrl-C ***
  474. break
  475.         movlw   0x39                ; Ctrl pressed
  476.         call    actualtransmit
  477.         movlw   0x99                ; C pressed & released
  478.         call    sendmessage
  479.         movlw   0x38                ; Ctrl released
  480.         call    actualtransmit
  481.         retlw   0x0          
  482.  
  483.  
  484.  
  485. ; *** Wait a long time ***
  486. longdelay
  487.         movwf   Count1
  488. dly
  489.         call    fixeddelay
  490.         decfsz  Count1,F
  491.         goto    dly
  492.         return
  493. ;
  494. ; *** Wait a short while ***
  495. fixeddelay
  496.         movlw   0xFF
  497. smalldelay
  498.         movwf   Count2
  499. delay
  500.         decfsz  Count2,F
  501.         goto    delay
  502.         return
  503.  
  504.  
  505.  
  506.  
  507. ; *** Send character to Amiga and wait for handshake ***
  508. amigatransmit
  509.         movwf   Amigachar
  510.         subwf   Oldchar,W
  511.         btfsc   STATUS,Z            ; skip if not equal
  512.         return                      ; ignore it
  513.         
  514.         movlw   0x33                ; LAmiga pressed
  515.         subwf   Amigachar,W
  516.         btfsc   STATUS,Z            ; skip if not equal
  517.         bcf     RESET,LAmigabit
  518.         movlw   0x32                ; LAmiga released
  519.         subwf   Amigachar,W
  520.         btfsc   STATUS,Z            ; skip if not equal
  521.         bsf     RESET,LAmigabit
  522.                 
  523.         movlw   0x31                ; RAmiga pressed
  524.         subwf   Amigachar,W
  525.         btfsc   STATUS,Z            ; skip if not equal
  526.         bcf     RESET,RAmigabit
  527.         movlw   0x30                ; RAmiga released
  528.         subwf   Amigachar,W
  529.         btfsc   STATUS,Z            ; skip if not equal
  530.         bsf     RESET,RAmigabit
  531.                 
  532.         movlw   0x3B                ; jump if not Capslock down
  533.         subwf   Amigachar,W
  534.         btfss   STATUS,Z            ; skip if equal
  535.         goto    transok2            ; ignore it
  536.         bcf     RESET,Ctrlbit
  537.         movf    Amigachar,W
  538.         movwf   Oldchar
  539.         movlw   0xFF
  540.         movwf   Capdown             ; set flags for later
  541.         return
  542. transok2
  543.         movlw   0x3A                ; jump if not Capslock up
  544.         subwf   Amigachar,W
  545.         btfss   STATUS,Z            ; skip if equal
  546.         goto    transok3            ; ignore it
  547.  
  548.         bsf     RESET,Ctrlbit
  549.         movlw   0x3B                ; see if Capslock was just down
  550.         subwf   Oldchar,W           ; 
  551.         btfss   STATUS,Z            ; skip if equal
  552.         goto    transok4            ; use as Ctrl key
  553.         clrf    Capdown             ; clear flag
  554.         comf    Capbit,F            ; toggle down/upness of caplock
  555.         movlw   0x3B                ; send Capslock down
  556.         btfss   Capbit,0x0
  557.         andlw   0xFE
  558.         call    actualtransmit
  559. ; send lights to AT
  560.         movlw   0xED                ; Next data is for lights
  561.         call    SendtoAT
  562.         bsf     Lights,CapsLock     ; Capslock on
  563.         btfss   Capbit,0x0
  564.         bcf     Lights,CapsLock     ; Capslock off
  565.         movf    Lights,W
  566.         call    SendtoAT
  567.         return
  568. transok4
  569.         btfsc   win95,0x0
  570.         return
  571.         clrf    CtrlDown
  572.         clrf    Capdown             ; Capslock has finished acting as ctrl
  573.         movlw   0x38                ; send Ctrl up
  574.         call    actualtransmit
  575.         return
  576. transok3
  577.         movf    Amigachar,W
  578.         movwf   Savechar2
  579.         movwf   Oldchar
  580.         movf    Capdown,F           ; Capslock down?
  581.         btfsc   STATUS,Z            ; skip if non-zero i.e caps pressed
  582.         goto    nocontrol           ; ignore it
  583.         btfsc   win95,0x0
  584.         goto    nocontrol           ; ignore it
  585.         movf    CtrlDown,F
  586.         btfss   STATUS,Z            ; skip if zero i.e caps pressed
  587.         goto    nocontrol           ; ignore it
  588.         movlw   0xFF
  589.         movwf   CtrlDown            ; Caps lock is now Ctrl key
  590.         movlw   0x39                ; send Ctrl down
  591.         call    actualtransmit
  592.         movf    Savechar2,W
  593.         goto    actualtransmit
  594. nocontrol
  595.         movf    Amigachar,W
  596.         andlw   0xFE
  597.         sublw   0x44                ; * (Numkey) released
  598.         btfss   STATUS,Z            ; skip if equal
  599.         clrf    AltConfig
  600.         incf    AltConfig,F
  601.  
  602.         movlw   0x28                ; 20 th time?
  603.         subwf   AltConfig,W
  604.         btfsc   STATUS,Z            ; skip if not equal
  605.         call    config
  606.  
  607.  
  608.         movf    Amigachar,W
  609.  
  610. actualtransmit
  611.         movwf   Amigachar
  612.  
  613.         movlw   .5           ; do a 5x256 delay
  614.         call    longdelay
  615. actual2
  616.         movlw   .8
  617.         movwf   Count1
  618.         clrf    Charbad
  619. f
  620.         btfsc   Amigachar,0x7       ; IF bit7=1 THEN Adat=1
  621.         bsf     PORTA,Adat
  622.         btfss   Amigachar,0x7       ; IF bit7=0 THEN Adat=0
  623.         bcf     PORTA,Adat
  624.         movlw   .8
  625.         call    smalldelay          ; Allow Adat logic to settle
  626.         bcf     PORTA,Aclk          ; transmit
  627.         movlw   .8
  628.         call    smalldelay          ; Allow Aclk logic to settle
  629.         bsf     PORTA,Aclk          ; reset Aclk=1
  630.         movlw   .10
  631.         call    smalldelay          ; Allow Aclk logic to settle
  632.         rlf     Amigachar,F
  633.         decfsz  Count1,F            ; Transmit next bit?
  634.         goto    f
  635.  
  636.         movlw   0xF
  637.         movwf   Count1
  638.         movlw   0xFF
  639.         movwf   Count1
  640.         movwf   Count2
  641.  
  642.         PAGE1          
  643.         bsf     TRISA,Adat          ; Read acknowledge signal
  644.         PAGE0          
  645. ack
  646.         decf    Count1,F
  647.         btfsc   STATUS,Z
  648.         decf    Count2,F
  649.         movf    Count2,W            ; Count2=0?
  650.         btfsc   STATUS,Z
  651.         goto    syncup              ; no handshake
  652.         btfsc   PORTA,Adat         ; wait for handshake from amiga
  653.         goto    ack
  654. ready
  655.         btfss   PORTA,Adat          ; wait for handshake to finish
  656.         goto    ready
  657.  
  658.         bsf     PORTA,Adat          ; reset Adat=1
  659.         PAGE1          
  660.         bcf     TRISA,Adat          ; Return to output mode
  661.         PAGE0          
  662.         return
  663. syncup
  664.         bcf     PORTA,Aclk          ; send another clock pulse
  665.         movlw   .8
  666.         call    smalldelay          ; Allow Aclk logic to settle
  667.         bsf     PORTA,Aclk          ; reset Aclk=1
  668.         movlw   0xFF
  669.         movwf   Count1
  670.         movwf   Count2
  671.         decf    Count3,F
  672.         btfsc   STATUS,Z
  673.         return
  674.         goto    ack                 ; wait for acknowledge again
  675.  
  676.  
  677.  
  678. ; *** Send character to AT keyboard and wait for handshake ***
  679. SendtoAT
  680.         movwf   Charbad
  681. resend
  682.         movf    Charbad,W
  683.         movwf   ATchar
  684.         clrf    ATparity
  685.         bsf     PORTB,Kclk          ; Kclk=1 get keyboards attention
  686.         nop
  687.         bcf     PORTB,Kdat          ; Kdat=0 get keyboards attention
  688.         PAGE1          
  689.         bcf     TRISB,Kclk          ; Kclk is in output mode
  690.         nop
  691.         bcf     TRISB,Kdat          ; Kdat is in output mode
  692.         PAGE0          
  693.         movlw   .8
  694.         movwf   Count1
  695.         PAGE1          
  696.         bsf     TRISB,Kclk          ; Kclk is in input mode
  697.         PAGE0          
  698. Send4   btfsc   PORTB,Kclk          ; wait for keyboard to make Kclk=0
  699.         goto    Send4
  700.         btfsc   ATchar,0x0          ; IF bit0=1 THEN Kdat=1
  701.         bsf     PORTB,Kdat
  702.         btfss   ATchar,0x0          ; IF bit0=0 THEN Kdat=0
  703.         bcf     PORTB,Kdat
  704.         rrf     ATchar,F            ; next bit
  705.         btfsc   STATUS,C            ; test parity of bit shifted out
  706.         incf    ATparity,F
  707. Send5   btfss   PORTB,Kclk          ; wait for keyboard to make Kclk=1
  708.         goto    Send5                
  709.         decfsz  Count1,F
  710.         goto    Send4
  711. Send6   btfsc   PORTB,Kclk          ; wait for keyboard to make Kclk=0
  712.         goto    Send6
  713.         btfsc   ATparity,0x0        ; IF bit0=odd THEN Kdat=0 (odd parity)
  714.         bcf     PORTB,Kdat
  715.         btfss   ATparity,0x0        ; IF bit0=even THEN Kdat=1 (odd parity)
  716.         bsf     PORTB,Kdat
  717. Send7   btfss   PORTB,Kclk          ; wait for keyboard to make Kclk=1
  718.         goto    Send7
  719. Send77  btfsc   PORTB,Kclk          ; wait for keyboard to make Kclk=0
  720.         goto    Send77
  721.         bsf     PORTB,Kdat          ; stop bit
  722. Send78  btfss   PORTB,Kclk          ; wait for keyboard to make Kclk=1
  723.         goto    Send78
  724.         PAGE1          
  725.         bsf     TRISB,Kdat          ; reset Kdat back to input mode
  726.         PAGE0          
  727. Send79  btfsc   PORTB,Kclk          ; wait for keyboard to make Kclk=0
  728.         goto    Send79
  729. Send7a  btfss   PORTB,Kclk          ; wait for keyboard to make Kclk=1
  730.         goto    Send7a
  731.         movlw   .8
  732.         call    smalldelay          ; Allow Kclk logic to settle
  733.         bcf     PORTB,Kclk          ; Kclk=0 Send handshake
  734.         PAGE1          
  735.         bcf     TRISB,Kclk          ; Kclk is in output mode
  736.         PAGE0          
  737.         movlw   .20
  738.         call    smalldelay          ; Allow keyboard chance 
  739.         call    ATgetkey
  740.         movlw   0xFA                ; Was transmission ok
  741.         subwf   ATchar,W
  742.         btfss   STATUS,Z            ; skip if good
  743.         goto    resend
  744.         return
  745.         
  746.  
  747.  
  748.  
  749. ; *** Waits for keyboard to send code ***
  750. ATgetkey
  751.         clrf    ATchar
  752.         bsf     PORTB,Kclk          ; Kclk=1 Allow keyboard to talk
  753.         PAGE1
  754.         bsf     TRISB,Kclk          ; Kclk is in input mode
  755.         PAGE0
  756. skip1st btfsc   PORTB,Kclk          ; wait for keyboard to make Kclk=0
  757.         goto    skip1st
  758. skippy  btfss   PORTB,Kclk          ; wait for keyboard to make Kclk=1
  759.         goto    skippy
  760.         movlw   .8
  761.         movwf   Count1
  762. ATwait0
  763.         btfsc   PORTB,Kclk          ; wait for keyboard to make Kclk=0
  764.         goto    ATwait0
  765.         rrf     ATchar,F
  766.         btfsc   PORTB,Kdat
  767.         bsf     ATchar,0x7
  768.         btfss   PORTB,Kdat
  769.         bcf     ATchar,0x7
  770. ATwait1 btfss   PORTB,Kclk          ; wait for keyboard to make Kclk=1
  771.         goto    ATwait1
  772.         decfsz  Count1,F
  773.         goto    ATwait0             ; get all 8 bits of data
  774. parity0 btfsc   PORTB,Kclk          ; wait for keyboard to make Kclk=0
  775.         goto    parity0
  776. parity1 btfss   PORTB,Kclk          ; wait for keyboard to make Kclk=1
  777.         goto    parity1
  778. stop0   btfsc   PORTB,Kclk          ; wait for keyboard to make Kclk=0
  779.         goto    stop0
  780. stop1   btfss   PORTB,Kclk          ; wait for keyboard to make Kclk=1
  781.         goto    stop1
  782.         bcf     PORTB,Kclk          ; Kclk=0 Send handshake
  783.         PAGE1
  784.         bcf     TRISB,Kclk          ; Kclk is in output mode
  785.         PAGE0
  786.         movlw   .20
  787.         call    smalldelay          ; Allow keyboard chance to recieve
  788.         return
  789.  
  790.  
  791.  
  792.  
  793.  
  794. ; *** Flash Light ***
  795. flash
  796.         movwf    Lights
  797.         movlw   0xED                ; Next data is for lights
  798.         call    SendtoAT
  799.         movf    Lights,W            ; Flash lights
  800.         call    SendtoAT
  801.         movlw   0x25
  802.         call    longdelay     
  803.         movlw   0xED                ; Next data is for lights
  804.         call    SendtoAT
  805.         movlw   0x0                 ; Clear Lights
  806.         call    SendtoAT
  807.         movlw   0x25
  808.         call    longdelay     
  809.         return
  810.  
  811.  
  812.  
  813. ; *** Performs reset on Amiga ***
  814. reset
  815.         movlw   Resetype
  816.         call    readdata
  817.         sublw   0x1                 
  818.         btfsc   STATUS,Z            ; skip if not equal
  819.         goto    kill                ; jump if fast reset
  820.         movlw   0x0F                ; Tell amiga we are going to reset it
  821.         call    actualtransmit
  822.  
  823.         movlw    0x8
  824.         movwf   Count3
  825. strobe  movlw    0x1
  826.         call    flash
  827.         movlw    0x2
  828.         call     flash
  829.         movlw    0x4
  830.         call     flash
  831.         decfsz  Count3,F
  832.         goto    strobe
  833. kill
  834.         movlw   0x70
  835.         call    longdelay     
  836.         bcf     PORTB,Arst          ; Arst=0 Send reset
  837.         PAGE1
  838.         bcf     TRISB,Arst          ; Arst is in output mode
  839.         PAGE0
  840.         movlw   0xFF
  841.         call    longdelay           ; Wait for Amiga to reset
  842.         goto    start2
  843.  
  844.  
  845.  
  846.  
  847. start
  848.  
  849. ; *** Allow time for HardDrive to spin upto speed ***
  850. SpinUp
  851.         bcf     PORTB,Arst          ; Arst=0 Send reset
  852.         PAGE1
  853.         bcf     TRISB,Arst          ; Arst is in output mode
  854.         PAGE0
  855.         movlw   0x30
  856.         movwf   Count3
  857. waitHD
  858.         movlw   0xFF
  859.         call    longdelay           ; Wait for drive to wake up
  860.         decfsz  Count3,F
  861.         goto    waitHD
  862.  
  863. start2
  864. ; *** Setup ports ***
  865.         bsf     PORTA,Aclk          ; transmit
  866.         nop
  867.         bsf     PORTA,Adat
  868.         PAGE1          
  869.         movlw   0x7
  870.         movwf   TRISA
  871.         movlw   0xFF
  872.         movwf   TRISB
  873.         PAGE0          
  874.  
  875.  
  876. ; *** Clear out miscellaneous flags ***
  877.         clrf    Capdown
  878.         clrf    CtrlDown
  879.         clrf    Capbit
  880.         clrf    Oldchar
  881.         clrf    AltConfig
  882.         movlw   0x7
  883.         movwf   RESET
  884.  
  885. ; *** See what sort of keyboard is attached ***
  886.         clrf    win95
  887.         movlw   Keytype
  888.         call    readdata
  889.         sublw   0x2                 
  890.         btfsc   STATUS,Z            ; skip if not equal
  891.         comf    win95               ; win95=true or false
  892.  
  893. ; *** Wait for AT keyboard to power up ***
  894. waitAT
  895.         btfss   PORTB,Kdat         ; wait for AT keyboard
  896.         goto    waitAT
  897.         
  898. ; *** Reset AT keyboard ***
  899. ;        movlw   0xFF            ; Reset
  900. ;        call    SendtoAT
  901.         movlw   0xF6            ; Default
  902.         call    SendtoAT
  903.         movlw    0x7
  904.         call    flash
  905.         movlw   0xED            ; Next data is for lights
  906.         call    SendtoAT
  907.         movlw   0x2
  908.         movwf   Lights
  909.         call    SendtoAT
  910.         movlw   0xF4            ; Clear buffer
  911.         call    SendtoAT
  912.  
  913.  
  914. ATstyle
  915.         movf    RESET,F
  916.         btfsc   STATUS,Z
  917.         goto    reset
  918.         call    ATgetkey
  919.         movlw   0xE1
  920.         subwf   ATchar,W
  921.         btfss   STATUS,Z            ; skip if equal
  922.         goto    ATnE1        
  923.         call    ATgetkey            ; should be $14
  924.         call    ATgetkey            ; should be $77
  925.         call    ATgetkey            ; should be $E1
  926.         call    ATgetkey            ; should be $F0
  927.         call    ATgetkey            ; should be $14
  928.         call    ATgetkey            ; should be $F0
  929.         call    ATgetkey            ; should be $77
  930.         goto    ATstyle
  931. ATnE1
  932.         clrf    tableoffset
  933.         movlw   0xE0
  934.         subwf   ATchar,W
  935.         btfss   STATUS,Z            ; skip if equal
  936.         goto    ATnE0        
  937.         movlw   0x80
  938.         movwf   tableoffset
  939.         call    ATgetkey
  940.         movlw   0xF0
  941.         subwf   ATchar,W
  942.         btfss   STATUS,Z            ; skip if equal
  943.         goto    ATnE0F0        
  944.         call    ATgetkey
  945.         movlw   0x12
  946.         subwf   ATchar,W
  947.         btfsc   STATUS,Z            ; skip if not equal
  948.         goto    ATstyle             ; E0F012 ignore it
  949. ATnEF12
  950.         movlw   0x59
  951.         subwf   ATchar,W
  952.         btfss   STATUS,Z            ; skip if equal
  953.         goto    ATup        
  954.         goto    ATstyle             ; E0F059 ignore it
  955. ATnE0F0
  956.         movlw   0x12
  957.         subwf   ATchar,W
  958.         btfsc   STATUS,Z            ; skip if not equal
  959.         goto    ATstyle             ; E012 ignore it
  960. ATnE012
  961.         movlw   0x59
  962.         subwf   ATchar,W
  963.         btfss   STATUS,Z            ; skip if equal
  964.         goto    ATdown        
  965.         goto    ATstyle             ; E059 ignore it
  966. ATnE0
  967.         movlw   0xF0
  968.         subwf   ATchar,W
  969.         btfss   STATUS,Z            ; skip if equal
  970.         goto    ATdown        
  971.         call    ATgetkey
  972.         goto    ATup                ; F0= key released
  973. ATdown        
  974.         incf    ATchar,W
  975.         addwf   tableoffset,W
  976.         call    ATtb1
  977.         addlw   0x0                 ; test W
  978.         btfss   STATUS,Z
  979.         call    amigatransmit
  980.         goto    ATstyle
  981. ATup        
  982.         incf    ATchar,W
  983.         addwf   tableoffset,W
  984.         movwf   tableoffset
  985.  
  986.         movlw   0xAF+1              ; menu key
  987.         subwf   tableoffset,W
  988.         btfsc   STATUS,Z            ; skip if not equal
  989.         goto    ATstyle             ; ignore it
  990.  
  991.         movlw   0x84+1              ; PrtScrn
  992.         subwf   tableoffset,W
  993.         btfsc   STATUS,Z            ; skip if not equal
  994.         goto    ATstyle             ; ignore it
  995.  
  996.         movlw   0xE9+1              ; End
  997.         subwf   tableoffset,W
  998.         btfsc   STATUS,Z            ; skip if not equal
  999.         goto    ATstyle             ; ignore it
  1000.  
  1001.         movlw   0xEC+1              ; Home
  1002.         subwf   tableoffset,W
  1003.         btfsc   STATUS,Z            ; skip if not equal
  1004.         goto    ATstyle             ; ignore it
  1005.  
  1006.         movlw   0xF0+1              ; Insert
  1007.         subwf   tableoffset,W
  1008.         btfsc   STATUS,Z            ; skip if not equal
  1009.         goto    ATstyle             ; ignore it
  1010.  
  1011.         movlw   0xFA+1              ; PageDown
  1012.         subwf   tableoffset,W
  1013.         btfsc   STATUS,Z            ; skip if not equal
  1014.         goto    ATstyle             ; ignore it
  1015.  
  1016.         movlw   0xFC+1              ; PrtScrn
  1017.         subwf   tableoffset,W
  1018.         btfsc   STATUS,Z            ; skip if not equal
  1019.         goto    ATstyle             ; ignore it
  1020.  
  1021.         movlw   0xFD+1              ; PageUp
  1022.         subwf   tableoffset,W
  1023.         btfsc   STATUS,Z            ; skip if not equal
  1024.         goto    ATstyle             ; ignore it
  1025.  
  1026.         movlw   0xFE+1              ; Break
  1027.         subwf   tableoffset,W
  1028.         btfsc   STATUS,Z            ; skip if not equal
  1029.         goto    ATstyle             ; ignore it
  1030.  
  1031.         movf    tableoffset,W
  1032.         call    ATtb1
  1033.         andlw   0xFE                ; clear bit 0
  1034.         call    amigatransmit
  1035.         goto    ATstyle
  1036.         
  1037.  
  1038.  
  1039.  
  1040.  
  1041.  
  1042.  
  1043.  
  1044.  
  1045.  
  1046.  
  1047.  
  1048.  
  1049.  
  1050. ; *** Change configuration ***
  1051. config
  1052.         clrf    eeaddress
  1053.         movlw   0x3B                ; CAPSLOCK ON
  1054.         call    actualtransmit
  1055.         
  1056.         call    say_select          ; Select Type of
  1057.         call    say_key             ; key
  1058.         movlw   0x95                ; b
  1059.         call    sendmessage
  1060.         movlw   0xCF                ; o
  1061.         call    sendmessage
  1062.         movlw   0xBF                ; a
  1063.         call    sendmessage
  1064.         movlw   0xD9                ; r
  1065.         call    sendmessage
  1066.         movlw   0xBB                ; d
  1067.         call    sendmessage
  1068.         call    say_option1         ; 1=
  1069.         call    say_uk10            ; uk 10
  1070.         movlw   0xFB                ; 2
  1071.         call    sendmessage
  1072.         movlw   0x7F                ; space
  1073.         call    sendmessage
  1074.         call    say_key             ; key
  1075.         call    say_option2         ; 2=
  1076.         call    say_uk10            ; uk 10
  1077.         movlw   0xF5                ; 5
  1078.         call    sendmessage
  1079.         movlw   0x7F                ; space
  1080.         call    sendmessage
  1081.         call    say_key             ; key
  1082.         movlw   0x7F                ; space
  1083.         call    sendmessage
  1084.         movlw   0xDD                ; w
  1085.         call    sendmessage
  1086.         movlw   0xD1                ; i
  1087.         call    sendmessage
  1088.         movlw   0x93                ; n
  1089.         call    sendmessage
  1090.         movlw   0xED                ; 9
  1091.         call    sendmessage
  1092.         movlw   0xF5                ; 5
  1093.         call    sendmessage
  1094.         movlw   0x77                ; return 
  1095.         call    sendmessage
  1096.         call    getselection
  1097.         movwf   eedata
  1098.         movf    eedata,W
  1099.         btfsc   STATUS,Z            ; skip if not zero
  1100.         goto    config              ; bad choice, try again
  1101.         call    writedata        
  1102.         call    say_ok
  1103.         clrf    win95
  1104.         movlw   Keytype
  1105.         call    readdata
  1106.         sublw   0x2                 
  1107.         btfsc   STATUS,Z            ; skip if not equal
  1108.         comf    win95               ; win95=true or false
  1109.  
  1110.         incf    eeaddress
  1111. askreset
  1112.         call    say_select          ; Select Type of
  1113.         call    say_reset           ; reset
  1114.         call    say_option1         ; 1=
  1115.         movlw   0xB9                ; f
  1116.         call    sendmessage
  1117.         movlw   0xBF                ; a
  1118.         call    sendmessage
  1119.         movlw   0xBD                ; s
  1120.         call    sendmessage
  1121.         movlw   0xD7                ; t
  1122.         call    sendmessage
  1123.         movlw   0x7F                ; space
  1124.         call    sendmessage
  1125.         call    say_reset           ; reset
  1126.         call    say_option2         ; 2=
  1127.         movlw   0xBD                ; s
  1128.         call    sendmessage
  1129.         movlw   0xAF                ; l
  1130.         call    sendmessage
  1131.         movlw   0xCF                ; o
  1132.         call    sendmessage
  1133.         movlw   0xDD                ; w
  1134.         call    sendmessage
  1135.         movlw   0x7F                ; space
  1136.         call    sendmessage
  1137.         call    say_reset           ; reset
  1138.         movlw   0x77                ; return 
  1139.         call    sendmessage
  1140.  
  1141.         call    getselection
  1142.         movwf   eedata
  1143.         movf    eedata,W
  1144.         btfsc   STATUS,Z            ; skip if not zero
  1145.         goto    askreset            ; bad choice, try again
  1146.         call    writedata        
  1147.         call    say_ok
  1148.  
  1149.         clrf    AltConfig
  1150.         movlw   0x7E                ; space up
  1151.         movf    Capdown,F           ; Capslock down?
  1152.         btfsc   STATUS,Z            ; skip if non-zero i.e caps pressed
  1153.         movlw   0x3A                ; Caps up
  1154.         movwf   Amigachar
  1155.         return
  1156.         
  1157. say_select
  1158.         movlw   0x77                ; return x2
  1159.         call    sendmessage
  1160.         call    sendmessage
  1161.         movlw   0xBD                ; s
  1162.         call    sendmessage
  1163.         movlw   0xDB                ; e
  1164.         call    sendmessage
  1165.         movlw   0xAF                ; l
  1166.         call    sendmessage
  1167.         movlw   0xDB                ; e
  1168.         call    sendmessage
  1169.         movlw   0x99                ; c
  1170.         call    sendmessage
  1171.         movlw   0xD7                ; t
  1172.         call    sendmessage
  1173.         movlw   0x7F                ; space
  1174.         call    sendmessage
  1175.         movlw   0xD7                ; t
  1176.         call    sendmessage
  1177.         movlw   0xD5                ; y
  1178.         call    sendmessage
  1179.         movlw   0xCD                ; p
  1180.         call    sendmessage
  1181.         movlw   0xDB                ; e
  1182.         call    sendmessage
  1183.         movlw   0x7F                ; space
  1184.         call    sendmessage
  1185.         movlw   0xCF                ; o
  1186.         call    sendmessage
  1187.         movlw   0xB9                ; f
  1188.         call    sendmessage
  1189.         movlw   0x7F                ; space
  1190.         call    sendmessage
  1191.         return
  1192.  
  1193. say_key
  1194.         movlw   0xB1                ; k
  1195.         call    sendmessage
  1196.         movlw   0xDB                ; e
  1197.         call    sendmessage
  1198.         movlw   0xD5                ; y
  1199.         call    sendmessage
  1200.         return
  1201.  
  1202. say_option1
  1203.        movlw   0x77                ; return x2
  1204.         call    sendmessage
  1205.         call    sendmessage
  1206.         movlw   0xFD                ; 1
  1207.         call    sendmessage
  1208.         movlw   0xE7                ; =
  1209.         call    sendmessage
  1210.         movlw   0x7F                ; space
  1211.         call    sendmessage
  1212.         return
  1213.  
  1214. say_option2
  1215.         movlw   0x77                ; return 
  1216.         call    sendmessage
  1217.         movlw   0xFB                ; 2
  1218.         call    sendmessage
  1219.         movlw   0xE7                ; =
  1220.         call    sendmessage
  1221.         movlw   0x7F                ; space
  1222.         call    sendmessage
  1223.         return
  1224.  
  1225. say_uk10
  1226.         movlw   0xD3                ; u
  1227.         call    sendmessage
  1228.         movlw   0xB1                ; k
  1229.         call    sendmessage
  1230.         movlw   0x7F                ; space
  1231.         call    sendmessage
  1232.         movlw   0xFD                ; 1
  1233.         call    sendmessage
  1234.         movlw   0xEB                ; 0
  1235.         call    sendmessage
  1236.         return
  1237.  
  1238. say_ok
  1239.         movlw   0xCF                ; o
  1240.         call    sendmessage
  1241.         movlw   0xB1                ; k
  1242.         call    sendmessage
  1243.         movlw   0x77                ; return
  1244.         call    sendmessage
  1245.         return
  1246.  
  1247. say_reset
  1248.         movlw   0xD9                ; r
  1249.         call    sendmessage
  1250.         movlw   0xDB                ; e
  1251.         call    sendmessage
  1252.         movlw   0xBD                ; s
  1253.         call    sendmessage
  1254.         movlw   0xDB                ; e
  1255.         call    sendmessage
  1256.         movlw   0xD7                ; t
  1257.         call    sendmessage
  1258.         return
  1259.  
  1260.  
  1261. sendmessage
  1262.         movwf   Savechar
  1263.         call    actualtransmit
  1264.         movf    Savechar,W
  1265.         andlw   0xFE
  1266.         call    actualtransmit
  1267.         movf    Savechar,W
  1268.         return        
  1269.  
  1270. getselection
  1271.         call    ATgetkey
  1272.         call    ATgetkey
  1273.         call    ATgetkey
  1274.         movlw   0x16                ; was key 1 pressed and released
  1275.         subwf   ATchar,W
  1276.         btfsc   STATUS,Z            ; skip if not equal
  1277.         retlw   0x1     
  1278.         movlw   0x1E                ; was key 2 pressed and released
  1279.         subwf   ATchar,W
  1280.         btfsc   STATUS,Z            ; skip if not equal
  1281.         retlw   0x2        
  1282.         retlw   0x0
  1283.  
  1284. writedata
  1285.         movf    eeaddress,W
  1286.         movwf   EEADR
  1287.         movf    eedata,W
  1288.         movwf   EEDATA
  1289.         PAGE1
  1290.         bsf     EECON1,WREN         ; EEPROM write enable
  1291.         movlw   0x55
  1292.         movwf   EECON2
  1293.         movlw   0xAA
  1294.         movwf   EECON2
  1295.         bsf     EECON1,WR
  1296. wait_write
  1297.         btfss   EECON1,EEIF         ; wait for write to finish
  1298.         goto    wait_write
  1299.         clrf    EECON1              ; EEPROM write disable & int accept
  1300.         PAGE0
  1301.         return
  1302.  
  1303.  
  1304. readdata
  1305.         movwf   EEADR
  1306.         PAGE1
  1307.         bsf     EECON1,RD           ; EEPROM read
  1308.         PAGE0
  1309.         movf    EEDATA,W
  1310.         return
  1311.  
  1312.  
  1313.  
  1314.  
  1315.  
  1316.  
  1317.  
  1318.         end
  1319.